<template>
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <el-form :inline="true" :model="listQuery" @submit.native.prevent ref="listQuery"  label-width="120px">
        <el-form-item label="用户名称" prop="userName" class="form-item">
          <el-input v-model="listQuery.userName" clearable class="filter-item" placeholder="用户名称"/>
        </el-form-item>
        <el-form-item label="开始时间:" class="form-item">
          <el-date-picker
            class="filter-item"
            popper-class="popperStyle"
            v-model="listQuery.startDate"
            type="date"
            clearable
            value-format="yyyy-MM-dd"
            placeholder="选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间:" class="form-item">
          <el-date-picker
            class="filter-item"
            popper-class="popperStyle"
            clearable
            v-model="listQuery.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="操作对象名称" class="form-item">
          <el-input v-model="listQuery.objectName" clearable class="filter-item" placeholder="操作对象名称"/>
        </el-form-item>
        <el-form-item label="操作对象类型" class="form-item">
          <el-input v-model="listQuery.objectType" clearable class="filter-item" placeholder="操作对象类型"/>
        </el-form-item>
        <el-form-item label="操作动作" class="form-item">
          <el-input v-model="listQuery.operate" clearable class="filter-item" placeholder="操作动作"/>
        </el-form-item >
        <el-form-item class="form-item">
          <el-button size="mini" icon="el-icon-refresh" @click="resetList">重置</el-button>
          <el-button type="primary" size="mini" icon="el-icon-search" @click="getList">查询</el-button>
        </el-form-item>
      </el-form>

      <div class="btn-btm">
        <el-form :inline="true" label-width="120px">
          <el-form-item label="删除时间:" class="form-item">
            <el-date-picker
              class="filter-item"
              popper-class="popperStyle"
              clearable
              v-model="delDate"
              type="date"
              @change="dateChange"
              value-format="yyyy-MM-dd"
              placeholder="选择删除时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item class="form-item">
            <el-button type="danger" size="mini" icon="el-icon-delete" :disabled="delDate == '' || delDate == null"
                       @click="delDateObj">删除</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <div class="table_content">
      <!--表格渲染-->
      <el-table ref="table" v-loading="loading" :data="list" style="width: 100%;"
                :header-cell-style="{background: '#F8F8F9',padding: '6px 0 !important',color: '#515a6e'}">
        <af-table-column fixed="left" prop="userName" label="登录用户名称"/>
        <af-table-column prop="operate" label="操作动作"/>
        <af-table-column prop="objectType" label="操作对象类型"/>
        <af-table-column prop="objectName" label="操作对象名称"/>
        <af-table-column prop="operate" label="操作动作"/>
        <af-table-column prop="description" label="操作描述信息"/>
        <af-table-column prop="timeOperate" label="操作时间"/>
      </el-table>
      <!--分页-->
      <pagination v-show="total>0" :total="total"
                  :page.sync="listQuery.pageNum"
                  :limit.sync="listQuery.pageSize"
                  @pagination="getList" />
    </div>

    <amend-pwd v-if="fistFlag == 0"></amend-pwd>
  </div>
</template>
<script>
  import { doPost, doGet } from '@/api/index'
  import Pagination from '@/components/Pagination/index'
  import { mapGetters } from 'vuex'

  export default {
    components: {
      Pagination
    },
    computed: {
      ...mapGetters([
        'name',
        'fistFlag'
      ])
    },
    data() {
      return{
        listQuery: {
          pageSize: 10,
          pageNum: 1,
          objectName: '',
          userName: '',
          startDate: '',
          operate: '',
          endDate: '',
          objectType: ''
        },
        list: [],
        total: 0,
        loading: true,
        delDate: ''
      }
    },
    created() {
      this.getList()
    },
    methods: {
      resetList() {
        this.listQuery = {
          pageSize: 10,
          pageNum: 1,
          objectName: '',
          userName: '',
          startDate: '',
          operate: '',
          endDate: '',
          objectType: ''
        }
      },
      getList() {
        this.loading = true
        doPost('syslog/page',this.listQuery).then(res => {
          this.list = res.data.list
          this.total = res.data.total
          this.loading = false
        }).catch(error => {
          this.list = []
          this.total = 0
          this.loading = false
        })
      },
      delDateObj() {
        /*if (this.delDate == '') {
          this.$message.error('删除时间不能为空')
          return
        }*/
        doPost('syslog/delete/'+this.delDate).then(res => {
            this.$message.success({
              type: 'success',
              message: '删除成功'
            })
            this.getList()
          }).catch(error => {
          this.$message.error(error.message)
        })
      },
      dateChange(e) {
        if (e == null ) {
          this.delDate = ''
        }
        console.log('delDate',this.delDate)
      }
    }
  }
</script>
<style lang="scss" scoped>

</style>
